package com.JobFind.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

import com.JobFind.DTO.DeliverBriefDTO;
import com.JobFind.DTO.DeliverShowDTO;

@Entity
@Table(name = "tb_deliver", catalog = "jobfind")
@Proxy(lazy = false)
public class TbDeliver implements java.io.Serializable {


	private static final long serialVersionUID = 1L;
	private Integer deliverId;
	private TbResume tbResume;
	private TbRecruitment tbRecruitment;
	private TbUser tbUser;
	private Integer deliverStatus;


	/** default constructor */
	public TbDeliver() {
	}

	/** full constructor */
	public TbDeliver(TbResume tbResume, TbRecruitment tbRecruitment,TbUser tbUser,Integer deliverStatus) {
		this.tbResume = tbResume;
		this.tbRecruitment = tbRecruitment;
		this.tbUser = tbUser;
		this.deliverStatus = deliverStatus;
	}

	@Id
	@GeneratedValue
	@Column(name = "DeliverId", unique = true, nullable = false)
	public Integer getDeliverId() {
		return this.deliverId;
	}

	public void setDeliverId(Integer deliverId) {
		this.deliverId = deliverId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ResumeId", nullable = false)
	public TbResume getTbResume() {
		return this.tbResume;
	}

	public void setTbResume(TbResume tbResume) {
		this.tbResume = tbResume;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RecruitmentId", nullable = false)
	public TbRecruitment getTbRecruitment() {
		return this.tbRecruitment;
	}

	public void setTbRecruitment(TbRecruitment tbRecruitment) {
		this.tbRecruitment = tbRecruitment;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "UserId", nullable = false)
	public TbUser getTbUser() {
		return tbUser;
	}

	public void setTbUser(TbUser tbUser) {
		this.tbUser = tbUser;
	}

	@Column(name="DeliverStatus", length=11)
	public Integer getDeliverStatus() {
		return deliverStatus;
	}

	public void setDeliverStatus(Integer deliverStatus) {
		this.deliverStatus = deliverStatus;
	}
	
	public DeliverShowDTO toDeliverShowDTO(){
		DeliverShowDTO deliverShowDTO = new DeliverShowDTO();
		deliverShowDTO.setDeliverId(this.getDeliverId());
		deliverShowDTO.setRecruitmentId(this.getTbRecruitment().getRecruitmentId());
		deliverShowDTO.setRecruitmentPosition(this.getTbRecruitment().getRecruitmentPosition());
		deliverShowDTO.setResumeId(this.getTbResume().getResumeId());
		deliverShowDTO.setUserId(this.getTbUser().getUserId());
		deliverShowDTO.setUserName(this.getTbUser().getUserNickName());
		return deliverShowDTO;
	}
	
	public DeliverBriefDTO toBriefDTO(){
		DeliverBriefDTO deliverBriefDTO = new DeliverBriefDTO();
		deliverBriefDTO.setDeliverId(this.getDeliverId());
		deliverBriefDTO.setRecruitmentId(this.getTbRecruitment().getRecruitmentId());
		deliverBriefDTO.setRecruitmentPosition(this.getTbRecruitment().getRecruitmentPosition());
		if(this.getDeliverStatus()==0)
			deliverBriefDTO.setDeliverStatus("未审核");
		else if (this.getDeliverStatus() == -1)
			deliverBriefDTO.setDeliverStatus("未通过");
		else 
			deliverBriefDTO.setDeliverStatus("已通过");
		return deliverBriefDTO;
	}
}